package com.shanghaiyimu.yimiyangche.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.shanghaiyimu.yimiyangche.R;

/**
 * 用来判断是否是第一次登陆
 * 是 跳转引导页
 * 否 跳转主界面
 */
public class EmptyActivity extends AppCompatActivity {
    private SharedPreferences mSharedPreferences;
    private boolean isFirst;
    private final int MAIN = 0x111;
    private final int GUIDE = 0x222;
    private Handler mHandler = new Handler(){

        @Override
        public void handleMessage(Message msg) {
            switch (msg.what){
                case MAIN:
                    Intent intent = new Intent(EmptyActivity.this,MainActivity.class);
                    startActivity(intent);
                    finish();
                    break;
                case GUIDE:
                    Intent intent2 = new Intent(EmptyActivity.this,WelcomeActivity.class);
                    startActivity(intent2);
                    finish();
                    break;
            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_empty);
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                mSharedPreferences = getSharedPreferences("conf",MODE_PRIVATE);
                isFirst = mSharedPreferences.getBoolean("first",true);
                if(isFirst){
                    SharedPreferences.Editor editor = mSharedPreferences.edit();
                    editor.putBoolean("first",false);
                    editor.commit();
                    Message msg = mHandler.obtainMessage();
                    msg.what = GUIDE;
                    mHandler.sendMessage(msg);
                }else{

                    Message msg = mHandler.obtainMessage();
                    msg.what = MAIN;
                    mHandler.sendMessage(msg);
                }

            }
        }, 2000);
    }
}
